package com.yhq.yhqproject.base.modules.base.job;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.yhq.yhqproject.base.modules.base.repo.BaseResultRepo;
import com.yhq.yhqproject.base.modules.base.service.ErrorLogService;
import com.yhq.yhqproject.base.modules.board.repo.TemplateHistoryRepo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class TemplateJob {

    @Resource
    private BaseResultRepo repo;

    @Resource
    private ErrorLogService errorLogService;

    @Resource
    private TemplateHistoryRepo templateHistoryRepo;

    @XxlJob("DeleteBaseResultJob")
    public ReturnT<String> deleteBaseResultJob() {
        log.info("执行定时任务-删除2分钟以前");
        long endTime = System.currentTimeMillis() - 1000 * 120;
        repo.deleteBaseResultByCreateTimeBefore(endTime);
        return ReturnT.SUCCESS;
    }

    @XxlJob("DeleteErrorJob")
    public ReturnT<String> deleteErrorJob() {
        log.info("执行定时任务-删除错误日志");
        errorLogService.delete3DayAgo();
        return ReturnT.SUCCESS;
    }

    @XxlJob("DeleteHistoryJob")
    public ReturnT<String> deleteHistoryJob() {
        log.info("执行定时任务-删除历史记录");
        templateHistoryRepo.delete3DayAgo();
        return ReturnT.SUCCESS;
    }

}
